<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>案例2</title>
    <link rel="stylesheet" href="../css/index.css">
    <style>
        .content {
            border: 2px solid orange;
            height: 400px;
            justify-content: space-evenly;
            padding: 20px 0;
        }
        
        .content div {
            height: 30px;
            width: 120px;
            background: orange;
            border: 0;
            color: #eee;
            text-align: center;
            line-height: 30px;
            cursor: pointer;
        }
    </style>
</head>

<body>
    <div class="content flex">
        <div onclick="getstyle()">Get Style</div>
        <div onclick="setstyle()">Set Sytle</div>
        <div onclick="defaultstyle()">Default Style</div>
    </div>

    <script>
        let temp = document.querySelector('.content.flex')
        let sx = ['width', 'height', 'border', 'display']
        let mystyle = temp.style

        function getstyle() {
            let str = ''
            sx.forEach(r => {
                str += `${r}:${getComputedStyle(temp)[r]}\n`
            });
            alert(str)
        }

        function setstyle() {
            temp.style.borderColor = 'red'
            temp.style.background = '#111'
        }

        function defaultstyle() {
            temp.style = mystyle
        }
    </script>
</body>

</html>